package sctu.edu.java.year2016.team01.renxinpeng.day20160610.chapter12_2;

import java.io.*;


/**
 * Created by Zero on 2016/6/12.
 * 使用字符输入、输出流读取文件，将一段文字加密后存入文件，在后再读取，并将加密前的文件与
 * 加密后的文件输出。。
 */
public class EncryptionFile {


    public void before() throws Exception{

        File file=new File("D:/","study.txt");


        FileOutputStream out =new FileOutputStream(file);
        byte study[]="好好学习!".getBytes();
        System.out.println("加密前文件");
        out.write(study);
        out.close();

    }

    public void after() throws Exception{

        File file=new File("D:/","study.txt");


        Reader in = new FileReader(file);
        char[] long1 = new char[30];
        int leng = -1;


        StringBuffer sb = new StringBuffer();

            while ((leng = in.read(long1))!=-1)
            {
                sb.append(new String(long1,0,leng));
            }


            in.close();
            System.out.println("加密后的文件：");
            System.out.println(sb);
        }


    public static void main(String[] args) throws Exception{

        EncryptionFile enncryptionFile=new EncryptionFile();


        enncryptionFile.before();

        enncryptionFile.after();

    }
}


